package com.tz.liveplayermodule.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tz.liveplayermodule.R;
import com.tz.liveplayermodule.bean.RalationDownloads;
import com.tz.liveplayermodule.util.CommonUtils;

import java.util.List;

/**
 * Created by tz on 2017/4/25.
 */

public class ListViewDownAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<RalationDownloads.ResultBean> mIntegralList;
    private Context mContext;
    private int mImgWidth, mImgHeight;

    public ListViewDownAdapter(Context context, List<RalationDownloads.ResultBean> integralList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        mIntegralList = integralList;
    }

    @Override
    public int getCount() {
        return mIntegralList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.item_down, null);
            holder = new ViewHolder();
            holder.play_item_title = (TextView) view.findViewById(R.id.play_item_title);
            holder.play_item_time_text = (TextView) view.findViewById(R.id.play_item_time_text);
            holder.play_item_size_text = (TextView) view.findViewById(R.id.play_item_size_text);
            holder.down_status = (TextView) view.findViewById(R.id.down_status);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        System.out.println("第" + i);

        holder.play_item_title.setText((i + 1) + "." + mIntegralList.get(i).getTitle());
        if (!CommonUtils.isEmpty(mIntegralList.get(i).getDuration())) {
            holder.play_item_time_text.setText(CommonUtils.secToTime(Integer.parseInt(mIntegralList.get(i).getDuration())));
        } else {
            holder.play_item_time_text.setText("0s");
        }
        if (mIntegralList.get(i).getInfo() != null) {
            holder.play_item_size_text.setText(CommonUtils.FormetFileSize((long) mIntegralList.get(i).getInfo().getSize()));
        } else {
            holder.play_item_size_text.setText("0KB");
        }

        if (mIntegralList.get(i).getType() == 0) {
            holder.down_status.setText("下载");
        } else if (mIntegralList.get(i).getType() == 1) {
            if (CommonUtils.isEmpty(mIntegralList.get(i).getProgress())) {
                holder.down_status.setText("下载中");
            } else {
                holder.down_status.setText("下载中:" + mIntegralList.get(i).getProgress() + "%");
            }
        } else if (mIntegralList.get(i).getType() == 2) {
            holder.down_status.setText("下载完成");
        }

        return view;
    }

    private class ViewHolder {
        TextView play_item_title;
        TextView play_item_time_text;
        TextView play_item_size_text;
        TextView down_status;
    }

}
